package cn.ztuo.bitrade.service;

import cn.ztuo.bitrade.dao.MemberLoginLogDao;
import cn.ztuo.bitrade.entity.Member;
import cn.ztuo.bitrade.entity.MemberLoginLog;
import cn.ztuo.bitrade.pagination.Criteria;
import cn.ztuo.bitrade.pagination.Restrictions;
import cn.ztuo.bitrade.service.Base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

/**
 * @author fiwork.net
 * @description
 * @date 2019/12/29 14:50
 */
@Service
public class MemberLoginLogService extends BaseService {
    @Autowired
    private MemberLoginLogDao loginLogDao;
    @Autowired
    private MemberService memberService;

    public Page<MemberLoginLog> pageQuery(Long userId,Integer pageNo, Integer pageSize) {
        //排序方式
        Sort orders = Criteria.sortStatic("loginTime.desc");
        //分页参数
        PageRequest pageRequest = new PageRequest(pageNo, pageSize, orders);
        //查询条件
        Criteria<MemberLoginLog> specification = new Criteria<MemberLoginLog>();
        specification.add(Restrictions.eq("userId", userId, true));
        return loginLogDao.findAll(specification, pageRequest);
    }
    public void save(MemberLoginLog loginLog) {
        loginLog = loginLogDao.save(loginLog);
    }


}
